feat(ramps-controller): share provider/quote/error helpers with consumers#9409
Draft
saustrie-consensys wants to merge 1 commit into
Draft
feat(ramps-controller): share provider/quote/error helpers with consumers#9409saustrie-consensys wants to merge 1 commit into
saustrie-consensys wants to merge 1 commit into
Conversation
…mers Expose the provider-availability, quote-classification, and error-normalization logic the controller uses internally as pure, tested helpers so headless-buy consumers (e.g. metamask-mobile) can share it instead of re-deriving it: - providerServesAsset, getProvidersServingAsset, regionHasProviderForAsset, isFiatDepositAvailable - isExternalBrowserQuote, isCustomActionQuote, isInAppOnlyQuote - getErrorMessage, extractExplicitTypedError, normalizeToTypedError (+ TypedError) RampsController now derives its own region asset-matching and quote filtering from these helpers so the shared surface stays behaviourally identical to the controller's selection.
75ef2c5 to
685219b
Compare
Contributor
Author
|
@metamaskbot publish-preview |
Contributor
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Explanation
Headless Buy provider expansion in
metamask-mobilere-derived logic thatRampsControlleralready owns privately: the CAIP-19 provider-serves-asset match, the scope-aware region/availability gate, the in-app-vs-external quote classification, and error-shape normalization. That duplication meant the UI gate could drift from the controller's own provider selection.This PR lifts that logic into pure, tested, exported helpers so consumers can share it instead of re-implementing it, and rewires the controller to consume the same helpers so the shared surface stays behaviourally identical to the controller's internal selection:
providerAvailability:providerServesAsset,getProvidersServingAsset,regionHasProviderForAsset,isFiatDepositAvailable.RampsController.#getSupportingProvidersForRegionnow uses the shared matcher.quoteClassification:isExternalBrowserQuote,isCustomActionQuote,isInAppOnlyQuote.RampsController.#pickInAppQuotenow uses these for its in-app filter.errorNormalization:getErrorMessage,extractExplicitTypedError,normalizeToTypedError(+TypedError<Code>). Consumers keep their own error-code taxonomy while sharing the extraction; the deliberately host-specific bits (deeplink schemes, redirect URLs, session lifecycle, error taxonomy values) stay in the consumer.No behaviour change for existing consumers: the helpers are additive, and the controller's refactored call sites are covered by the existing suite (all 579 package tests pass, plus 42 new helper tests).
References
@metamask/ramps-controller@^15.2.0)app/components/UI/Ramp/headless/PLAN_-_ALL_PROVIDERS_SUPPORT.mdin metamask-mobile)Checklist
Made with Cursor